package com.vict.util;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import java.io.File;
public class TesseractExample {
    public static void main(String[] args) {
        File imageFile = new File("D:\\3.png");
        ITesseract instance = new Tesseract();  // JNA Interface Mapping
        // 语言库的路径
        // instance.setDatapath("D:\\TessData\\tessdata\\tessdata-master");
        // 通过环境变量获取
        instance.setDatapath("D:\\AAAAAAAAAAAAAAAAAAAA\\WorkSpace\\JavaImgText\\chi2");
        //instance.setDatapath("D:\\AAAAAAAAAAAAAAAAAAAA\\WorkSpace\\JavaImgText");
        // 设置语言为中文， eng为英文
        instance.setLanguage("chi_sim");
        //instance.setLanguage("eng");
        try {
            long startTime = System.currentTimeMillis();

            // 执行OCR操作
            String result = instance.doOCR(imageFile);
            System.out.println(result);

            long endTime = System.currentTimeMillis();
            System.out.println("Time is：" + (endTime - startTime) + " 毫秒");
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }
}
